<template>
  <div>
    <el-cascader
      v-model="value"
      :options="normalizedOptions"
      :placeholder="'请选择'"
      style="width:100%;"
      :props="{multiple:true}"
      @change="handleChange">
    </el-cascader>
  </div>
</template>

<script lang='ts'>
    import { Component, Prop, Vue } from 'vue-property-decorator';
    import { getCategoryExList } from '@/base/api/LvApi';

    @Component
    export default class UserSelector extends Vue {
        @Prop({ type: String })
        readonly targetProducts! : string;

        value: Array<any>=[];
        options: Array<any>=[];
        temp = '';
        normalizedOptions:Array<any>=[];
        async created () {
            await getCategoryExList().then((res) => {
                // @ts-ignore
                let that = JSON.stringify(res.data);
                this.normalizedOptions = JSON.parse(that
                    .replace(/categoryId/g, 'value')
                    .replace(/sortName/g, 'label')
                );
            });
            if (this.targetProducts) {
                this.value = JSON.parse(this.targetProducts);
            }
        }
        handleChange(value) {
            // console.log(value);
            this.$emit('change', value, 2)
        }
    }
</script>

<style scoped>
  /deep/ .popper .el-cascader-panel .el-checkbox{
    padding: 10px 50px;
  }
</style>
